/*
    Project:        Home Power Control
    File:           HPCWindVane.h
    Author:         christian@karunamusic.at
    Date:           02.2015
    Description:    Sensor to measure the direction of the wind.
                    The sensor works with 8 reed-switches connected to different resistors.
                    The magnet can close 2 switches so that we have 16 positions.
                    The output of the voltage-divider is measured via MCP3008 (A2D).
 */

#ifndef HPCWINDVANE_H
#define HPCWINDVANE_H

#include <QString>
#include <HPCSensor.h>
#include "Sensors/Extensions/HPCMCP3008.h"

/** \brief Sensor to measure the direction of wind.
 *  Gives the direction as value from 1 (North) to 16 (North/NorthWest) or 0 (invalid).
 *  Measures the output of the voltage-divider via mcp3008.
 */
class HPCWindVane : public HPCSensor
{
    Q_OBJECT
public:
    /** \brief Constructor
     *
     * \param name name of the sensor.
     * \param id database id of the sensor.
     * \param channel The SPI channel of the connected mcp3008.
     * \param pin Inputpin of the mcp3008.
     */
    explicit HPCWindVane( const QString& name, quint32 id, quint8 channel, quint8 pin );
    /** \brief Destructor.
     */
    virtual ~HPCWindVane();

    /** \brief Get the SPI channel.
     *
     * \return The SPI channel (0/1).
     */
    inline quint8 Channel() const
      { return m_Channel; }

    inline void Channel(quint8 c)
      { m_Channel = c; }

    /** \brief Get class with content as printable string.
     *
     * \return string
     */
    virtual QString asString() const;

protected:
    /** \brief Get a value from the sensor.
     */
    virtual void Measure();

private:
    quint8 m_Channel;  /**<  SPI channel */
    HPCMCP3008 *m_A2D; /**< The A/D converter-chip MCP3008 */
};

#endif // HPCWINDVANE_H
